// 顶部：仅类型导入
import type { ILogger } from './logger';
import { DEFAULT_LEVEL, LoggerLevel } from './config';
export {
    LoggerLevel,
}
export type {
    ILogger,
}

class Logger implements ILogger {
    private readonly _name: string;
    private readonly _level: LoggerLevel;

    constructor(name: string, level?: LoggerLevel) {
        this._name = name;
        this._level = level ?? DEFAULT_LEVEL;
    }

    static LoggerLevel = LoggerLevel;

    debug(message: string, ...optionalParams: any[]): void {
        if (this._level <= LoggerLevel.Debug) {
            console.debug(`[${this._name}] DEBUG: ${message}`, ...optionalParams);
        }
    }

    info(message: string, ...optionalParams: any[]): void {
        if (this._level <= LoggerLevel.Info) {
            console.info(`[${this._name}] INFO: ${message}`, ...optionalParams);
        }
    }

    warn(message: string, ...optionalParams: any[]): void {
        if (this._level <= LoggerLevel.Warn) {
            console.warn(`[${this._name}] WARN: ${message}`, ...optionalParams);
        }
    }

    error(message: string, ...optionalParams: any[]): void {
        if (this._level <= LoggerLevel.Error) {
            console.error(`[${this._name}] ERROR: ${message}`, ...optionalParams);
        }
    }

    fatal(message: string, ...optionalParams: any[]): void {
        if (this._level <= LoggerLevel.Error) {
            console.error(`[${this._name}] FATAL: ${message}`, ...optionalParams);
        }
    }
}

export default Logger;
